<template>
  <div>
    <van-tabs v-model:active="formData.active" swipeable @change="onClickTab">
      <van-tab :title="item.name" v-for="(item,index) in tabList" :key="index">
        <van-pull-refresh v-model="formData.refreshing" @refresh="onRefresh" v-if="DataList.length>0">
          <van-list v-model:loading="formData.loading" :finished="formData.finished" finished-text="我也是有底线的~" @load="onload" :immediate-check="false">
            <ul v-if="DataList.length">
              <li v-for="(item,index) in DataList" :key="index" @click="GoOrder(item.userOrderId)">
                <van-row class="li">
                  <van-col span="8">
                    <div class="videoContainer" v-if="!VideoIndexOf(item.collectionCover)">
                      <video :src="item.collectionCover" />
                    </div>
                    <div class="img-box" v-if="VideoIndexOf(item.collectionCover)">
                      <img :src="item.collectionCover" class="img" />
                    </div>
                  </van-col>
                  <van-col span="11" class="line">
                    <div class="record-cont">
                      <h1>{{item.collectionName}} </h1>
                      <h2>{{item.className?item.className:""}}</h2>
                      <h2>购买数量：{{item.number?item.number:"1"}}</h2>
                      <p>{{item.payTime?item.payTime:item.createTime}}</p>
                    </div>
                  </van-col>
                  <van-col span="5" class="space-between">
                    <span :class="{'green': item.status == 1}">{{item.status==1?"已支付":item.status==0?"待支付":"已取消"}}</span>
                    <p>￥ {{item.amount}}</p>
                  </van-col>
                </van-row>
              </li>
            </ul>

          </van-list>
        </van-pull-refresh>
        <van-empty :image="require('@/assets/image/none.png')" description="暂无订单记录" v-if="DataList.length==0" />
      </van-tab>

    </van-tabs>

  </div>
  <!-- <van-tabs v-model:active="active" v-for="(item,index) in tabList" :key="index">
    <van-tab :title="item.name"></van-tab>
  </van-tabs> -->

</template>
<script>
import { ref, defineComponent, reactive, onMounted, toRefs, nextTick, computed } from "vue";
import { ipageByUserCollection, ipageByUserBlindBox } from "@/api/public";
import { Toast } from "vant";
import { useStore } from "vuex";
import { useRouter } from "vue-router"
import { VideoIndexOf } from "@/utils/phone";
import video from "@/components/video.vue";
export default {
  components: { video },
  setup() {
    const DataList = ref([])
    const store = useStore();
    const router = useRouter()
    const user_info = computed(() => {
      return store.getters.user_info
    })
    const menList = reactive([
      {
        id: 0, name: "藏品"
      },
      {
        id: 3, name: "盲盒"
      },
      // {
      //   id: 2, name: "市场"
      // }

    ])
    const formData = reactive({
      tab: 0,
      pageNum: 1,
      pageSize: 10,
      active: 0,
      total: 0,
      type: null,
      loading: true,
      finished: false,
      isActive: true,
      hasError: false,
      propType: 0

    })
    const getTab = async (id) => {
      DataList.value = []
      formData.tab = id
      formData.propType = id
      formData.pageNum = 1
      formData.loading = false

      formData.refreshing = true
      onload()
    }
    const GoOrder = (id) => {

      router.push({
        path: '/Orderdetails',
        // /details
        query: {
          id: id
        }
      })
    }
    const onRefresh = () => {
      DataList.value = []
      formData.pageNum = 1
      formData.total = 0
      formData.loading = false
      formData.finished = false
      formData.refreshing = true
      Toast('刷新成功');

      onload()

    }
    const onClickTab = (index) => {

      console.log(index)
      // formData.finished = true,
      //   formData.loading = false
      formData.pageNum = 1
      DataList.value = []
      let num = index - 1
      if (num < 0) {
        formData.type = null
      } else {
        formData.type = num
      }
      onload()

    }
    onMounted(() => {
      onload()
    })
    const onload = async () => {

      formData.finished = false
      formData.loading = true
      console.log(formData.finished, formData.loading)
      const data = {
        pageNum: formData.pageNum,
        pageSize: formData.pageSize,
        status: formData.type,
        userId: store.getters.user_info.id
      }
      console.log(store.getters.user_info, " store.getters.user_info.id")
      const res = await ipageByUserCollection(data)
      formData.loading = false
      formData.total = res.data.data.total
      DataList.value = DataList.value.concat(res.data.data.records)
      formData.pageNum++
      if (formData.finished) {
        formData.loading = true
      }
      if (formData.refreshing) {
        formData.refreshing = false
      }
      console.log(formData.total, DataList.value.length)
      if (res.data.data.records.length == 0) {
        formData.pageNum = 1
        formData.loading = false
        formData.finished = true;
      } else {
        if (formData.total == DataList.value.length) {
          console.log("不加载")
          formData.finished = true;
          formData.loading = false
          return false
        } else {
          formData.finished = false;
          console.log("加载")

        }
      }


    }
    const tabList = reactive([
      {
        id: 0,
        name: '全部'
      },
      {
        id: 0,
        name: '待付款'
      },
      {
        id: 0,
        name: '已付款'
      },

      {
        id: 0,
        name: '已取消'
      }

    ])
    return {
      menList,
      onload,
      tabList,
      formData,
      onRefresh,
      DataList,
      onClickTab,
      GoOrder,
      getTab,
      VideoIndexOf
    }
  }

}
</script>

<style lang="less" scoped>
.videoContainer {
  background: linear-gradient(0deg, #161718, #4b4c4d);
  border: 2px solid #ffffff;
  border-radius: 20px;
  overflow: hidden;
  width: 200px;
  height: 200px;
  video {
    width: 200px;
    height: 200px;
  }
  .fullscreenVideo {
    width: 100%;
  }
}
&:deep(.van-tabs__wrap) {
  background: transparent;
}
&:deep(.van-tabs__nav) {
  background: transparent !important;
  margin: 0px 20px;
}
&:deep(.van-tab) {
  font-size: 31px;
  font-family: Source Han Sans CN;
  font-weight: 400;
  color: #ffffff;
  opacity: 0.8;
}
&:deep(.van-tab--active) {
  .van-tab__text {
    font-size: 36px;
    font-family: Source Han Sans CN;
    font-weight: bold;
    line-height: 30px;
    background: linear-gradient(-90deg, #37dc6d 0%, #34d1f9 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
  }
}
&:deep(.van-tabs__line) {
  background: url('../../../../assets/image/tab-active.png');
  background-size: 100% 100%;
  bottom: 40px !important;
}
ul {
  margin: 0px 20px;
  li {
    background: #282a2c;
    border-radius: 20px;
    margin-top: 30px;
    padding: 20px 20px 40px;
    .img-box {
      width: 200px;
      height: 200px;
      background: linear-gradient(0deg, #161718, #4b4c4d);
      border: 2px solid #ffffff;
      border-radius: 20px;
      overflow: hidden;
      img {
        width: 100%;
        height: 100%;
      }
    }
    .record-cont {
      h1 {
        height: 30px;
        font-size: 32px;
        font-family: Source Han Sans CN;
        font-weight: 400;
        color: #ffffff;
        line-height: 53px;
        margin: 0px;
      }
      h2 {
        height: 25px;
        font-size: 26px;
        font-family: Source Han Sans CN;
        font-weight: 400;
        color: #b9c4c7;
        line-height: 48px;
        margin-top: 25px;
      }
      p {
        height: 20px;
        font-size: 26px;
        font-family: Source Han Sans CN;
        font-weight: 300;
        color: #b9c4c7;
        line-height: 48px;
      }
    }
    .space-between {
      display: flex;
      flex-direction: column;
      justify-content: space-between;
      align-items: flex-end;
      span {
        font-size: 32px;
        font-family: Source Han Sans CN;
        font-weight: 400;
        color: #ffffff;
        line-height: 73px;

        background: linear-gradient(-90deg, #37dc6d 0%, #34d1f9 100%);
        -webkit-background-clip: text;
        -webkit-text-fill-color: transparent;
      }
      p {
        font-size: 40px;
        font-family: Source Han Sans CN;
        font-weight: bold;
        color: #ffffff;
        line-height: 73px;

        background: linear-gradient(-90deg, #37dc6d 0%, #34d1f9 100%);
        -webkit-background-clip: text;
        -webkit-text-fill-color: transparent;
      }
    }
  }
}
.title {
  .tabactive {
    font-size: 36px !important;
    font-weight: bold !important;
    color: #ffffff !important;
  }
  padding-left: 20px;
  height: 80px;
  background: #222;
  display: flex;
  align-items: center;
  &:deep(.icon) {
    color: #ffffff;
    font-size: 50px;
  }
  .tab {
    padding-left: 40px;
    span {
      font-size: 36px;
      font-family: Source Han Sans CN;
      font-weight: 400;
      color: #b9c4c7;
      display: inline-block;
      margin-right: 80px;
    }
  }
}
</style>